﻿package view.tips
{
    import com.core.*;
    import com.core.display.*;
    import com.greensock.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;

    public class Marquee extends Sprite
    {
        private var posType:int = 0;
        private var msgDic:Dictionary;
        private var size:int = 0;
        private var time:int = 0;

        public function Marquee()
        {
            this.msgDic = new Dictionary();
            return;
        }// end function

        public function addToStack(param1:int, param2:Object) : void
        {
            param2.curTime = 0;
            if (param2.interval == 0)
            {
                this.doShow(param2);
            }
            else if (this.msgDic[param1])
            {
                this.msgDic[param1].push(param2);
            }
            else
            {
                this.msgDic[param1] = [param2];
                var _loc_3:String = this;
                var _loc_4:* = this.size + 1;
                _loc_3.size = _loc_4;
                if (this.size == 1)
                {
                    this.time = setInterval(this.doTime, 100);
                }
            }
            return;
        }// end function

        public function multiAddToStack(param1:Array) : void
        {
            var _loc_2:Object = null;
            for each (_loc_2 in param1)
            {
                
                this.addToStack(_loc_2.type, _loc_2.msg);
            }
            return;
        }// end function

        private function doTime() : void
        {
            var _loc_1:String = null;
            var _loc_2:Array = null;
            var _loc_3:Object = null;
            for (_loc_1 in this.msgDic)
            {
                
                _loc_2 = this.msgDic[_loc_1];
                _loc_3 = _loc_2[0];
                var _loc_6:* = _loc_3;
                var _loc_7:* = _loc_3.curTime + 1;
                _loc_6.curTime = _loc_7;
                if (_loc_3.curTime >= _loc_3.interval)
                {
                    _loc_3 = _loc_2.shift();
                    this.doShow(_loc_3);
                    if (_loc_2.length == 0)
                    {
                        delete this.msgDic[_loc_1];
                        var _loc_6:String = this;
                        var _loc_7:* = this.size - 1;
                        _loc_6.size = _loc_7;
                        if (this.size == 0)
                        {
                            clearInterval(this.time);
                            this.time = 0;
                        }
                    }
                }
            }
            return;
        }// end function

        private function doShow(param1:Object) : void
        {
            var _loc_4:Object = null;
            var _loc_5:Point = null;
            var _loc_2:* = new TextField();
            _loc_2.defaultTextFormat = param1.textFormat ? (param1.textFormat) : (new TextFormat("宋体", 20, 14786337));
            _loc_2.htmlText = param1.content;
            _loc_2.autoSize = TextFieldAutoSize.LEFT;
            _loc_2.mouseEnabled = false;
            this.addChild(_loc_2);
            switch(int(param1.posType))
            {
                case 1:
                {
                    if (mouseX + _loc_2.width + 50 > GlobalLayer.instance.root.stage.stageWidth)
                    {
                        _loc_2.x = GlobalLayer.instance.root.stage.stageWidth - _loc_2.width - 50;
                    }
                    else
                    {
                        _loc_2.x = mouseX;
                    }
                    _loc_2.y = mouseY;
                    break;
                }
                case 2:
                {
                    _loc_4 = UserData.getUserData();
                    _loc_5 = ModelProxy.getValue("data", "stagePos");
                    _loc_2.x = _loc_4.x * 48 - 24 + _loc_5.x - this.x;
                    _loc_2.y = _loc_4.y * 32 - 172 + _loc_5.y - this.y;
                    break;
                }
                case 3:
                {
                    _loc_2.x = GlobalLayer.instance.root.width - _loc_2.width >> 1;
                    _loc_2.y = GlobalLayer.instance.root.height - _loc_2.height >> 1;
                    break;
                }
                case 4:
                {
                    _loc_2.x = GlobalLayer.instance.root.width - _loc_2.width >> 1;
                    _loc_2.y = (GlobalLayer.instance.root.height - _loc_2.height) * 3 >> 2;
                    break;
                }
                case 5:
                {
                    _loc_2.x = param1.showPos.x;
                    _loc_2.y = param1.showPos.y;
                    break;
                }
                default:
                {
                    break;
                }
            }
            if (!param1.tweenMsg)
            {
                if (param1.toPos)
                {
                    param1.tweenMsg = {x:_loc_2.x + param1.toPos.x, y:_loc_2.y + param1.toPos.y};
                }
                else
                {
                    param1.tweenMsg = {y:_loc_2.y - 70};
                }
            }
            else if (param1.toPos)
            {
                param1.tweenMsg.y = _loc_2.y + param1.toPos.y;
                param1.tweenMsg.x = _loc_2.x + param1.toPos.x;
            }
            else
            {
                param1.tweenMsg.y = _loc_2.y - 70;
            }
            var _loc_3:* = param1.tweenMsg;
            _loc_3.onComplete = this.doRemove;
            _loc_3.onCompleteParams = [_loc_2];
            TweenLite.to(_loc_2, param1.showTime, _loc_3);
            return;
        }// end function

        public function doRemove(param1:TextField) : void
        {
            this.removeChild(param1);
            param1 = null;
            return;
        }// end function

    }
}
